<%-- 
    Document   : index
    Created on : Dec 3, 2013, 9:42:29 PM
    Author     : Welcome
--%>

<%@page import="bc.entity.Hoadon"%>
<%@page import="businesscard.DAO.UserDAO"%>
<%@page import="bc.entity.User"%>
<%@page import="bc.entity.Binhluan"%>
<%@page import="businesscard.DAO.BinhluanDAO"%>
<%@page import="bc.entity.Lienhe"%>
<%@page import="businesscard.DAO.LienheDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="css/bocuc.css" type="text/css"/>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
        <link rel="stylesheet" href="css/trangcanhan.css" type="text/css"/>
        <link rel="stylesheet" href="css/testcss.css" type="text/css"/>
        <link rel="stylesheet" href="css/mystyle.css" type="text/css"/>
        <link rel="stylesheet" href="css/botoncss.css" type="text/css"/>
        <script type="text/javascript" src="jquery/jquery-1.1.3.1.min.js"></script> 
        <script type="text/javascript" src="jquery/jquery-1.4.2.js"></script> 
        <script type="text/javascript" src="jquery/jquery-latest.js"></script>
        <script type="text/javascript" src="jquery/myjquery.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

        <title>Businesscard</title>
         <script type="text/javascript" src="jquery/jquery-1.8.0.min.js"></script>

      
          <script type="text/javascript" >
              
            $(function() {
                $(".inputsearch").keyup(function()
                {
                    var searchid = $(this).val();
                    var dataString = 'search=' + searchid;
                    if (searchid !== '')
                    {
                        $.ajax({
                            type: "POST",
                            url: "searchAjax.jsp",
                            data: dataString,
                            cache: false,
                            success: function(html)
                            {
                                $("#showhint").html(html).show();
                            }
                        });
                    }else{
                         jQuery("#showhint").hide();
                    }
                    return false;
                });

                jQuery("#showhint").live("click", function(e) {
                    var $clicked = $(e.target);
                    var $name = $clicked.find('.name').html();
                    var decoded = $("<div/>").html($name).text();
                    $('#searchid').val(decoded);
                });
                jQuery(document).live("click", function(e) {
                    var $clicked = $(e.target);
                    if (!$clicked.hasClass("inputsearch")) {
                        jQuery("#showhint").fadeOut();
                    }
                });
                $('#searchid').click(function() {
                    jQuery("#showhint").fadeIn();
                });
                
            });
        </script>
        <style type="text/css">
         //body{ 
         //       font-family:Tahoma, Geneva, sans-serif;
         //       font-size:18px;
         //   }
        //    .content{
        //        width:900px;
        //        margin:0 auto;
        //    }
            .name{
                width:446px;
                
                margin-top:-1px !important;
                background-color:transparent !important;
                margin-left:0;}
            #showhint
            {
                position:absolute;
                width:446px;
                padding:10px;
                display:none;
                margin-top:-1px;
                border-top:0px;
                overflow:hidden;
                border:1px #CCC solid;
                background-color: white;
                margin-left: 423px;
            }
            .show
            {
                padding:10px; 
                border-bottom:1px #999 dashed;
                font-size:15px; 
                height:50px;
            }
            .show:hover
            {
                background:#4c66a4;
                color:#FFF;
                cursor:pointer;
            }
            .name:hover
            {
                background:#4c66a4;
                color:#FFF;
                cursor:pointer;
            }
        </style>
        <script>
            var xmlhttp
            function AddCart(str)
            {
                xmlhttp = GetXmlHttpObject();

                if (xmlhttp == null)
                {
                    alert("Your browser does not support Ajax HTTP");
                    return;
                }
                var url = "addCart.jsp";
                url = url + "?id=" + str;

                xmlhttp.onreadystatechange = getOutput;
                xmlhttp.open("GET", url, true);
                xmlhttp.send(null);
            }

            function getOutput()
            {
                // if (xmlhttp.readyState==4)
                // {
                document.getElementById("soluong").innerHTML = xmlhttp.responseText;
                //  }
            }

            function GetXmlHttpObject()
            {
                if (window.XMLHttpRequest)
                {
                    return new XMLHttpRequest();
                }
                if (window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                return null;
            }
        </script>
    </head>
    <body>
        <div class="bodypage">
            <!phan dau cua trang>
            <div class="top">
                <%@include file='header.jsp'%>
            </div>
            <!phan search>
            <div class="khoangcachtrang">
                <div class="searchgroup">

                    <%@include file='search.jsp' %> 
                    <div class="chontimkiem">
                        <a href="timkiemnangcao.jsp">Tìm Kiếm Nâng Cao</a>
                    </div>

                </div>
            </div>

            <!phan giua trang >
            <div class="centerpage">

                <div class="leftsite">
                    <div class="menuweb">
                        <%@include file='menuleft.jsp' %>
                    </div>
                </div>
                <div class="content">
                    <div class="khoangtrang"></div>
                    
                    <div class="centerindex ">

                        <%
                            int idlienhe =Integer.parseInt(request.getParameter("malienhe"));
                            LienheDAO lhDAO = new LienheDAO();
                            Lienhe lh = lhDAO.getLienHe1(idlienhe);

                            int id_lienhe = lh.getIdLienhe();
                            int id_congty = lh.getCongty().getIdCongty();
                            String congty = lhDAO.getTenCongty(id_congty);
                            String ten = lh.getTen();
                            String tell = lh.getSdtcodinh();
                            String mobi = lh.getSdt();
                            String fax = lh.getFax();
                            String email1 = lh.getEmail();
                            String diachi = lh.getDiachi();
                            String huyen = lh.getQuanhuyen().getQuanhuyen();
                            String tinh = lh.getQuanhuyen().getThanhpho().getThanhpho();
                            String capbac = lh.getCapbac().getCapbac();
                            String bophan = lh.getBophan().getBophan();
                            int dongia = lh.getCapbac().getDongia();
                        %>

                        <div class="ctlienhe">
                            <div class="tencty"><%=congty%></div>
                            <div class="tenlh"><%=ten%></div>
                            <div class="capbac"><%=capbac%> - bộ phận <%=bophan%></div>
                            <div class="add">Add:<%=diachi + ", huyện " + huyen + ", tỉnh " + tinh%></div>
                            <%
                                HttpSession session2 = request.getSession();
                                User user3 = (User) session2.getAttribute("USER");
                                if (user3 != null) {
                                    String username1 = user3.getUser();
                                    UserDAO userDAO1 = new UserDAO();
                                    User user4 = userDAO1.getUser2(username1);
                                    int id_user = user4.getIdUser();
                                    boolean c = false;
                                    Hoadon[] HD = lhDAO.getHoadonLH(id_user);
                                    for (int k = 0; k < HD.length; k++) {
                                        if (HD[k].getLienhe().getIdLienhe() == id_lienhe) {
                                            c = true;
                                        }
                                    }
                                    if (dongia == 0 || (dongia != 0 && c == true) || (dongia != 0 && id_user == lh.getUser().getIdUser())) {
                            %>
                            <div class="tell">Tell:<%=tell%> </div>
                            <div class="tell">Mobile:<%=mobi%></div>
                            <div class="tell">Fax:<%=fax%></div>
                            <div class="tell">Email:<%=email1%></div>
                            <%
                            } else {
                            %>
                            <div class="giohang"><button style="" type="submit" onclick="AddCart(<%=id_lienhe%>);" ><image src="images/cart.png"/></button></div>
                            <p style="color:red">Tiến hành mua Liên hệ để thấy được thông tin!</p>
                            <%                                                                            }
                            } else {

                                if (dongia == 0) {
                            %>
                            <div class="tell">Tell:<%=tell%> </div>
                            <div class="tell">Mobile:<%=mobi%></div>
                            <div class="tell">Fax:<%=fax%></div>
                            <div class="tell">Email:<%=email1%></div>  
                            <%
                            } else {
                            %>
                            <p style="color:red">Mời bạn đăng nhập để có thể nhìn thấy thông tin!</p>
                            <%                                                                                }
                                }%>
                        </div>
                         <div class="khoangtrang"></div>
                         <div class="commentindex">
                        <%
                            BinhluanDAO A = new BinhluanDAO();
                            Binhluan[] B = A.getAllBinhluan(id_lienhe);
                            if (B != null) {
                                for (int j = 0; j < B.length; j++) {
                        %>
                        
                        <div class="commentctlh">
                            <div class="hinhdaidienctlh">
                                <%
                                    int id = B[j].getUser().getIdUser();
                                    String link1 = "avatar/" + A.getLinkHinh(id);
                                %>
                                <image src="<%=link1%>" style="width: 50px; height: 50px;"/>
                            </div>
                            <div class="usercmtctlh"><%=B[j].getBinhluan()%></div>

                        </div>
                        <%
                                }
                            }
                        %>
                        </div>
                        <div class="like"><a href="#">Like</a></div>
                        
                        <div class="binhluan">
                            <form action="CommentController" method="post">
                                <input type="text" name="binhluan" value=" " placeholder="Viết bình luận..." />
                                <input type="hidden" name="binhluanhide" value="<%=id_lienhe%>"/>
                                <input type="submit" value="Bình luận" name="action" />   
                            </form>
                        </div>

                    </div>
                                <div class="khoangtrang"></div>
                </div>

            </div>
            <!phan cuoi trang>
            <div class="footer">
                <div class="footerleft"></div>
                <div class="footerright"></div>
            </div>
        </div>
    </body>
</html>
